<?php
// +----------------------------------------------------------------------
// | 基础控制器
// +----------------------------------------------------------------------
namespace app\admin\controller;
use app\common\controller\Admin;
use Request;
use think\File;

class Base extends Admin {

    public function _initialize() {
    	parent::_initialize();
    }

    /**
     * 文件和图片
     */
    public function upload(){
        $this->isAuth('admin.base.upload');
        if(request()->isPost()){
            $file = Request::file();
            $temp = array_key_exists('file',$file)?$file['file']:$file['imgFile'];
            $filename = $temp->validate(['size'=>config('upfile_size'),'ext'=>config('upfile_ext')])->move(config('upfile_path'));
            if ($filename){
                $str['error'] = 0;
                $str['url'] = "/res/uploads/".$filename->getSaveName();
            }else{
                $str['error'] = 1;
                $str['message'] = $file->getError();
            }
            return json($str); 
        }else{
            $input = input('input/s');
            $this->assign('input',$input);
            return $this->fetch(); 
        }
    }
}
